package com.hutu.comment.service.impl;

import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.hutu.comment.domain.TbUserCollectedQuestion;
import com.hutu.comment.domain.dto.QuestionCollectedDto;
import com.hutu.comment.mapper.TbUserCollectedQuestionMapper;
import com.hutu.comment.service.TbUserCollectedQuestionService;
import org.springframework.stereotype.Service;

/**
* @author 20272
* @description 针对表【tb_user_collected_question(用户收藏问题记录表)】的数据库操作Service实现
* @createDate 2025-03-17 22:08:45
*/
@Service
public class TbUserCollectedQuestionServiceImpl extends MppServiceImpl<TbUserCollectedQuestionMapper, TbUserCollectedQuestion>
    implements TbUserCollectedQuestionService{

    @Override
    public Boolean saveOrDeleteCollectedQuestion(QuestionCollectedDto questionCollectedDto) {
        // 根据 flag 来判断是删除还是收藏
        if (questionCollectedDto == null){
            return false;
        }
        Integer flag = questionCollectedDto.getFlag();
        TbUserCollectedQuestion question = new TbUserCollectedQuestion();
        question.setQuestionId(questionCollectedDto.getQuestionId());
        question.setUsername(questionCollectedDto.getUsername());
        if (1 == flag){
            return save(question);
        } else {
            // 取消收藏
            return deleteByMultiId(question);
        }
    }
}




